<?php
class JobAction extends GlobalAction{
	public function index(){
	$this->job_list();
	}
	public function job_list(){
    	$job = M('job');
    	import("@.ORG.Page"); //导入分页类 
        $count = $job->count();    //计算总数 
        $p = new Page ( $count, 20 ); 
    	$job = $job->limit($p->firstRow.','.$p->listRows)->order('job_id asc')->findall();
    	$page = $p->show (); 
        $this->assign( "page", $page ); 
    	$this->assign('job',$job);
    	$this->GlobalName();
		$this->display('list');
    }
    
    public function add(){
    	$sort = M('job');
    	$sort = $sort->distinct('distinct')->Field('sort,e_sort')->findall();
    	$this->assign('sort',$sort);
    	$this->GlobalName();
		$this->display();
    }
    public function job_news_get(){
    	$_POST['time'] = time();
    	$_POST['stoptime'] = strtotime($_POST['stoptime']);
    	$job = M('job');
    	$job->create();
    	if ($job->add()) {
    		$this->get_alert('新增成功');
    	};
    }
    
    public function edit(){
    	$pid = $_GET['pid'];
    	$job = M('job');
    	$job = $job->where('job_id = '.$pid)->findall();
    	$this->assign('job',$job);
    	$sort = M('job');
    	$sort = $sort->distinct('distinct')->Field('sort,e_sort')->findall();
    	$this->assign('sort',$sort);
    	$this->GlobalName();
		$this->display();
    }
    public function job_edit_get(){
    	$_POST['stoptime'] = strtotime($_POST['stoptime']);
    	$job = M('job');
    	$job->create();
    	if ($job->save()) {
    		$this->get_alert('修改成功');
    	};
    }
    
    public function job_delete(){
    	$job = M('job');
    	$del = $_POST['del'];
    	$delete = $del[0];
    	for ($i=1;$i < count($del);$i++){
    		$delete = $delete.','.$del[$i];
    	}
    	if ($job->delete($delete)) {
    		$this->get_alert('删除成功');
    	};
    }
    
    public function ajax_show(){
    	$this->ajax_get('job','show_m');
    }
    public function left(){//默认左列表
    	$left = array(
    		array('sort'=>'Job','name'=>'职位管理','value'=>'job_list'),
    		array('sort'=>'Job','name'=>'新增职位','value'=>'add')
    	);
     	$this->assign('user',$_SESSION['User']);
    	$this->assign('sort',$sort);
    	$this->assign('left',$left);
    	$this->display('Index:left');
    }
}
?>